<template>
  <div>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <div class="mb-3">中奖记录</div>

        <el-form :model="listQuery" inline>
          <el-form-item prop="start_date">
            <el-date-picker
              v-model="listQuery.start_date"
              clearable
              value-format="yyyy-MM-dd"
              type="date"
              placeholder="请选择开始时间"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item prop="end_date">
            <el-date-picker
              v-model="listQuery.end_date"
              clearable
              value-format="yyyy-MM-dd"
              type="date"
              placeholder="请选择结束时间"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-select
              v-model="listQuery.gift_id"
              clearable
              filterable
              placeholder="请选择礼物"
            >
              <el-option
                v-for="item in giftlistOptions"
                :key="item.id"
                :value="item.id"
                :label="item.name"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-input
              clearable
              placeholder="请输入用户昵称或用户id"
              v-model="listQuery.keyword"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              style="float: right"
              @click="deBounceWrap(handleSearch)"
              icon="el-icon-search"
              >搜索
            </el-button>
          </el-form-item>
        </el-form>
      </div>
      <el-table v-loading="loading" :data="recordData" border>
        <el-table-column prop="id" label="用户ID"></el-table-column>
        <el-table-column prop="user_code" label="用户编号"></el-table-column>
        <el-table-column prop="nickname" label="用户昵称"></el-table-column>
        <el-table-column prop="gift_name" label="中奖名称"></el-table-column>
        <el-table-column prop="type" label="所属类型">
          <template slot-scope="{ row }">
            <el-tag
              :color="
                row.type === 1
                  ? '#a9a9a9'
                  : row.type === 2
                  ? '#dac90a'
                  : '#b89c5b'
              "
              >{{ row.type | typeFilter }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="number" label="数量"></el-table-column>
        <el-table-column prop="add_time" label="中奖时间"></el-table-column>
      </el-table>

      <cus-pagination
        v-show="total > 0"
        :total="total"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.per_page"
        @pagination="getRecordList"
      />
    </el-card>
  </div>
</template>
<script>
import { giftlist } from "@/api/blindBox";
import { recordList } from "@/api/blindBox/winningRecord";

export default {
  name: "winningRecord",
  data() {
    return {
      loading: false,
      listQuery: {
        start_date: undefined,
        end_date: undefined,
        gift_id: undefined,
        keyword: undefined,
        page: 1,
        perpage: 10
      },
      total: 0,
      recordData: [],
      giftlistOptions: [],
      pond_type: 8,
      tagText: "铜盲盒"
    };
  },
  created() {
    this.getGiftList();
    this.getRecordList();
  },
  filters: {
    typeFilter(value) {
      if (value === 1) {
        return "银盲盒";
      } else if (value === 2) {
        return "金盲盒";
      } else if (value === 3) {
        return "铜盲盒";
      }
    }
  },
  methods: {
    getGiftList() {
      giftlist(this.pond_type).then(res => {
        this.giftlistOptions = res.data;
      });
    },
    getRecordList() {
      this.loading = true;
      recordList(this.listQuery).then(
        ({
          data: {
            list: { data, total }
          }
        }) => {
          this.total = total;
          this.recordData = data;
          this.loading = false;
        }
      );
    },
    handleSearch() {
      this.listQuery.page = 1;
      this.getRecordList();
    }
  }
};
</script>

<style scoped>
.el-tag {
  color: white;
}
</style>
